package com.fysports.web.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.ext.kit.RequestWarpper;
import com.jfinal.log.Log;
import com.fysports.web.api.APIException;
import com.fysports.web.module.view.OperateType;

/**
 *  移动端请求拦截处理<br>
 *  与authenticationinterceptor交叉验证
 *  Create by konbluesky
 *  Date :15-11-13 下午13:02:06
 */
public class MobileAuthenticationInterceptor implements Interceptor {
    private static Log log = Log.getLog(MobileAuthenticationInterceptor.class);


    @Override public void intercept(Invocation ai) {
        try {
            RequestWarpper rw=new RequestWarpper(ai.getController().getRequest());
            if(rw.isMobileReq()) {
                /**
                 * do check
                 */
                if(true){
                    ai.invoke();
                }else{
                    throw new APIException(OperateType.BAD_REQUEST.getStrVal(),rw.getMType(),ai.getControllerKey());
                }
            }else{
                //web请求 直接过滤
                ai.invoke();
            }
        }
        catch (Exception e) {
            log.error(e.getMessage(),e);
            throw e;
        }
    }
}
